function admin_model()
{
	//#################################################################
	//
	// 입력부
	//
	//#################################################################
	// 중복 체크
	$( '#btnCheckModelCode' ).click(function(e) {
        $.post( getGatePath()
		,
		{
			__key__: 'isSameModelCode',
			__returnType__: 'json',
			code: $( '#insertModelForm' ).find( 'input[name="code"]' ).val()
		}
		,
		function( data )
		{
			if( data.result == "SUCCESS" )
			{
				setResult( '[모델 관리코드 중복체크] 사용 가능한 코드' );
			}else{
				setResultFailForJSON( '[모델 관리코드 중복체크] 사용 불가능한 코드', data );
			}
		}
		,
		'json' );
    });
	
	// 모델 입력
	$( '#insertModelForm' ).submit(function(e) {
        e.preventDefault();
		
		var _formData = new FormData( document.getElementById( 'insertModelForm' ) );
		_formData.append( '__key__', 'insertModel' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 추가] 성공' );
				}else{
					setResultFailForJSON( '[모델 추가] 실패', data );
				}
			}
		});
    });
	
	//#################################################################
	//
	// 조회부
	//
	//#################################################################
	// 목록 조회
	var _listPage 	= new PageInfo( document.getElementById( 'selectModels' ) );
	$( "#modelRefresh" ).click(function(e) {
		selectAllModels( _listPage.current, _listPage.numPerPage, modelRefreshSuccess, modelRefreshFail );
	});
	
	// 조회 성공
	function modelRefreshSuccess( data )
	{
		// 성공 핸들러
		setResult( '[모델 조회] 성공' );
		
		var $listContainer = $( "#selectModels>.list" );
		// 비우기
		$listContainer.find( '.btnEdit' ).unbind( "click" );
		$listContainer.find( '.btnDelete' ).unbind( "click" );
		$listContainer.empty();
		
		// 타이틀 추가
		var _tr;
		_tr = "<thead>";
		_tr += "<tr>";
		_tr += 		"<td>NO</td>";
		_tr +=  	"<td>CODE</td>";
		_tr +=  	"<td>이름</td>";
		_tr +=  	"<td>대표이미지</td>";
		_tr +=  	"<td>출생일</td>";
		_tr +=  	"<td>출생지</td>";
		_tr +=  	"<td>최종학력</td>";
		_tr +=  	"<td>성별</td>";
		_tr +=  	"<td>병역</td>";
		_tr +=  	"<td>키</td>";
		_tr +=  	"<td>자료출처</td>";
		_tr +=  	"<td>EDIT</td>";
		_tr +=  	"<td>DELETE</td>";
		_tr += "</tr>";
		_tr += "</thead>";
		_tr += "<tbody>";
		// 리스트 추가
		var _no = (_listPage.current-1)*_listPage.numPerPage+1;
		for( var index in data.model )
		{
			var _item = data.model[ index ];
			_tr += "<tr>";
			_tr += 		"<td>"+(_no++)+"</td>";
			_tr += 		"<td>"+_item[ 'code' ]+"</td>";
			_tr += 		"<td>"+_item[ 'name' ]+"</td>";
			_tr += 		"<td>"+_item[ 'picture' ]+"</td>";
			_tr += 		"<td>"+_item[ 'birth_date' ]+"</td>";
			_tr += 		"<td>"+toStringByRegion( _item[ 'birth_region' ] )+"</td>";
			_tr += 		"<td>"+toStringByEducation( _item[ 'last_edu' ] )+"</td>";
			_tr += 		"<td>"+toStringBySex( _item[ 'sex' ] )+"</td>";
			_tr += 		"<td>"+toStringByMilitary( _item[ 'military' ] )+"</td>";
			_tr += 		"<td>"+_item[ 'height' ]+"</td>";
			_tr += 		"<td>"+_item[ 'ref' ]+"/"+_item[ 'ref_license' ]+"</td>";
			_tr += 		"<td>"+"<input type='button' class='btnEdit' value='EDIT' data='"+_item[ 'code' ]+"'/>"+"</td>";
			_tr += 		"<td>"+"<input type='button' class='btnDelete' value='DELETE' data='"+_item[ 'code' ]+"'/>"+"</td>";
			_tr += "</tr>";
		}
		_tr += "</tbody>";
		$listContainer.append( _tr );
		
		// 수정 버튼 이벤트 등록
		$listContainer.find( '.btnEdit' ).bind( "click", null, function(e) {
			// alert( 'EDIT '+$(this).attr( 'data' ) );
			var $model_code = $(this).attr( 'data' );
			showUpdateModelPopup( $model_code );
		});
		// 삭제 버튼 이벤트 등록
		$listContainer.find( '.btnDelete' ).bind( "click", null, function(e) {
			alert( '미구현 :: DELETE '+$(this).attr( 'data' ) );
		});
		
		// 페이징
		_listPage.setTotalCount( data.count );
		_listPage.updateLabelField();
	}
	
	// 조회 실패
	function modelRefreshFail( data )
	{
		setResultFailForJSON( '[모델 조회] 실패', data );
	};
	
	// 상세 팝업 활성
	function showUpdateModelPopup( $model_code )
	{
		$.post( getGatePath(),
			{
				__key__: 'selectModel',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				modelCode: $model_code
			}, 
			function( data )
			{
				if( data.result == "SUCCESS" )
				{
					setResult( '[모델 상세 정보 조회] 성공' );
					
					// [[ 팝업 셋팅 ]]
					$popup = $( "#updateModel" );
					$popup.show();
					
					// 팝업이 설정과 동시에 공통변수 설정
					$popup.find( '.modelCode' ).val( data[ 'code' ] );
					
					$popup.find( '[name="code"]' ).val(		data[ 'code' ] );
					$popup.find( '[name="name"]' ).val( 	data[ 'name' ] );
					
					// 썸네일 정보
					var _thumbnails = null;
					if( data[ 'thumbnails' ] )
					{
						_thumbnails = data[ 'thumbnails' ][ 'thumb' ];
					}
					setPicture( $popup
								, { seq: data[ 'code' ], link: data[ 'picture' ] }
								, _thumbnails );
					
					// 기타 설정
					$popup.find( '[name="birthDate"]' ).val( 		data[ 'birth_date' ] );
					$popup.find( '[name="birthRegion"]' ).val( 		data[ 'birth_region' ] );
					$popup.find( '[name="education"]' ).val( 		data[ 'last_edu' ] );
					$popup.find( '[name="education_memo"]' ).val( 	data[ 'last_edu_memo' ] );
					$popup.find( '[name="sex"]' ).val( 				data[ 'sex' ] );
					$popup.find( '[name="military"]' ).val( 		data[ 'military' ] );
					$popup.find( '[name="military_memo"]' ).val( 	data[ 'military_memo' ] );
					$popup.find( '[name="height"]' ).val( 			data[ 'height' ] );
					$popup.find( '[name="ref"]' ).val( 				data[ 'ref' ] );
					$popup.find( '[name="ref_license"]' ).val( 		data[ 'ref_license' ] );
					
					// 정당 히스토리
					selectModelParty( $model_code );
					// 직책 히스토리
					selectModelDuty( $model_code );
					// 약력 히스토리
					selectModelHistory( $model_code );
					// 당선 히스토리
					selectModelElection( $model_code );
					// 발의 법안
					selectModelBussiness( $model_code );
					// SNS
					selectModelSns( $model_code );
					// TAG
					selectModelTags( $model_code );
				}else{
					setResultFailForJSON( '[모델 상세 정보 조회] 실패', data );
				}
			},
			'json' );
	}
	
	// 상세 팝업 수정
	$( '#updateModelForm' ).submit(function(e) {
		e.preventDefault();
		
		var _formData = new FormData( document.getElementById( 'updateModelForm' ) );
		_formData.append( '__key__', 'updateModel' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 기본 정보 수정] 성공' );
					
					$( "#modelRefresh" ).click();
				}else{
					setResultFailForJSON( '[모델 기본 정보 수정] 실패', data );
				}
			}
		});
    });
	
	
	//#################################################################
	//
	// 정당 정보
	//
	//#################################################################
	// 추가
	$( '#insertModelPartyForm' ).submit(function(e) {
        e.preventDefault();
		
		var _formData = new FormData( document.getElementById( 'insertModelPartyForm' ) );
		_formData.append( '__key__', 'insertModelParty' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 정당 추가] 성공' );
					
					// 리스트 갱신
					selectModelParty( data[ 'code' ] );
				}else{
					setResultFailForJSON( '[모델 정당 추가] 실패', data );
				}
			}
		});
    });
	// 조회
	function selectModelParty( $model_code )
	{
		var $container = $( '#modelPartyList table' );
		$container.empty();
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelParty',
				__returnType__: 'json',
				modelCode: $model_code
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 정당 조회] 성공' );
					
					// 비우기
					$container.find( '.btnDelete' ).unbind( "click" );
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>SEQ</td>";
					_tr +=  	"<td>활동시작</td>";
					_tr +=  	"<td>활동종료</td>";
					_tr +=  	"<td>정당</td>";
					_tr +=  	"<td>코멘트</td>";
					_tr +=  	"<td>DELETE</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;//(_listPage.current-1)*_listPage.numPerPage+1;
					for( var index in data.party )
					{
						var _item = data.party[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'seq' ]+"</td>";
						_tr += 		"<td>"+_item[ 'start' ]+"</td>";
						_tr += 		"<td>"+_item[ 'end' ]+"</td>";
						_tr += 		"<td>"+toStringByParty( _item[ 'p_code' ] )+"</td>";
						_tr += 		"<td>"+_item[ 'memo' ]+"</td>";
						_tr += 		"<td>"+"<input type='button' class='btnDelete' value='DELETE' data='"+_item[ 'seq' ]+"'/>"+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$container.append( _tr );
					
					// 삭제 버튼 이벤트 등록
					$container.find( '.btnDelete' ).bind( "click", null, function(e) {
						//alert( '미구현 :: DELETE '+$(this).attr( 'data' ) );
						deleteModelParty( $model_code, $(this).attr( 'data' ) );
					});
					
				}else{
					setResultFailForJSON( '[모델 정당 조회] 실패', data );
				}
			}
			,
			'json' );
	}
	// 삭제
	function deleteModelParty( $model_code, $modelParty_seq )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'deleteModelParty',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				seq: $modelParty_seq
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 정당 삭제] 성공' );
					
					// 리스트 갱신
					selectModelParty( $model_code );
				}else{
					setResultFailForJSON( '[모델 정당 삭제] 실패', data );
				}
			}
			,
			'json' );
	}
	
	
	//#################################################################
	//
	// 직책 정보
	//
	//#################################################################
	// 추가
	$( '#insertModelDutyForm' ).submit(function(e) {
        e.preventDefault();
		
		var _formData = new FormData( document.getElementById( 'insertModelDutyForm' ) );
		_formData.append( '__key__', 'insertModelDuty' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 직책 추가] 성공' );
					
					// 리스트 갱신
					selectModelDuty( data[ 'code' ] );
				}else{
					setResultFailForJSON( '[모델 직책 추가] 실패', data );
				}
			}
		});
    });
	// 조회
	function selectModelDuty( $model_code )
	{
		var $container = $( '#modelDuty>.list' );
		$container.empty();
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelDuty',
				__returnType__: 'json',
				modelCode: $model_code
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 직책 조회] 성공' );
					
					// 비우기
					$container.find( '.btnDelete' ).unbind( "click" );
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>SEQ</td>";
					_tr +=  	"<td>임무시작</td>";
					_tr +=  	"<td>임무종료</td>";
					_tr +=  	"<td>소속 당</td>";
					_tr +=  	"<td>직급</td>";
					_tr +=  	"<td>직책</td>";
					_tr +=  	"<td>완수여부</td>";
					_tr +=  	"<td>메모</td>";
					_tr +=  	"<td>DELETE</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;//(_listPage.current-1)*_listPage.numPerPage+1;
					for( var index in data.duty )
					{
						var _item = data.duty[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'seq' ]+"</td>";
						_tr += 		"<td>"+_item[ 'start' ]+"</td>";
						_tr += 		"<td>"+_item[ 'end' ]+"</td>";
						_tr += 		"<td>"+toStringByParty( _item[ 'p_code' ] )+"</td>";
						_tr += 		"<td>"+toStringByRank( _item[ 'r_code' ] )+"</td>";
						_tr += 		"<td>"+toStringByDuty( _item[ 'd_code' ] )+"</td>";
						_tr += 		"<td>"+toStringByCompleted( _item[ 'com_code' ] )+"</td>";
						_tr += 		"<td>"+_item[ 'memo' ]+"</td>";
						_tr += 		"<td>"+"<input type='button' class='btnDelete' value='DELETE' data='"+_item[ 'seq' ]+"'/>"+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$container.append( _tr );
					
					// 삭제 버튼 이벤트 등록
					$container.find( '.btnDelete' ).bind( "click", null, function(e) {
						//alert( '미구현 :: DELETE '+$(this).attr( 'data' ) );
						deleteModelDuty( $model_code, $(this).attr( 'data' ) );
					});
					
				}else{
					setResultFailForJSON( '[모델 직책 조회] 실패', data );
				}
			}
			,
			'json' );
	}
	// 삭제
	function deleteModelDuty( $model_code, $modelDuty_seq )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'deleteModelDuty',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				seq: $modelDuty_seq
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 직책 삭제] 성공' );
					
					// 리스트 갱신
					selectModelDuty( $model_code );
				}else{
					setResultFailForJSON( '[모델 직책 삭제] 실패', data );
				}
			}
			,
			'json' );
	}
	
	
	//#################################################################
	//
	// 약력 정보
	//
	//#################################################################
	// 추가
	$( '#insertModelHistoryForm' ).submit(function(e) {
        e.preventDefault();
		
		var _formData = new FormData( document.getElementById( 'insertModelHistoryForm' ) );
		_formData.append( '__key__', 'insertModelHistory' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 약력 추가] 성공' );
					
					// 리스트 갱신
					selectModelHistory( data[ 'code' ] );
				}else{
					setResultFailForJSON( '[모델 약력 추가] 실패', data );
				}
			}
		});
    });
	// 조회
	function selectModelHistory( $model_code )
	{
		var $container = $( '#updateModelHistoryOrdersForm>.list' );
		$container.empty();
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelHistory',
				__returnType__: 'json',
				modelCode: $model_code
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 약력 조회] 성공' );
					
					// 비우기
					$container.find( '.btnDelete' ).unbind( "click" );
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>SEQ</td>";
					_tr +=  	"<td>구분</td>";
					_tr +=  	"<td>시작일</td>";
					_tr +=  	"<td>종료일</td>";
					_tr +=  	"<td>타이틀</td>";
					_tr +=  	"<td>우선순위</td>";
					_tr +=  	"<td>DELETE</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;//(_listPage.current-1)*_listPage.numPerPage+1;
					for( var index in data.history )
					{
						var _item = data.history[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td><input name='seq[]' type='text' value='"+_item[ 'seq' ]+"' readonly='readonly' style='width:3em;'/></td>";
						_tr += 		"<td>"+toStringByHistory( _item[ 'h_code' ] )+"</td>";
						_tr += 		"<td>"+_item[ 'start' ]+"</td>";
						_tr += 		"<td>"+_item[ 'end' ]+"</td>";
						_tr += 		"<td>"+_item[ 'memo' ]+"</td>";
						_tr += 		"<td><input name='order[]' type='text' value='"+_item[ 'order' ]+"' style='width:3em;'/></td>";
						_tr += 		"<td>"+"<input type='button' class='btnDelete' value='DELETE' data='"+_item[ 'seq' ]+"'/>"+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$container.append( _tr );
					
					// 삭제 버튼 이벤트 등록
					$container.find( '.btnDelete' ).bind( "click", null, function(e) {
						//alert( '미구현 :: DELETE '+$(this).attr( 'data' ) );
						deleteModelHistory( $model_code, $(this).attr( 'data' ) );
					});
					
				}else{
					setResultFailForJSON( '[모델 약력 조회] 실패', data );
				}
			}
			,
			'json' );
	}
	// 삭제
	function deleteModelHistory( $model_code, $modelHistory_seq )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'deleteModelHistory',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				seq: $modelHistory_seq
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 약력 삭제] 성공' );
					
					// 리스트 갱신
					selectModelHistory( $model_code );
				}else{
					setResultFailForJSON( '[모델 약력 삭제] 실패', data );
				}
			}
			,
			'json' );
	}
	// 우선순위 갱신
	$( '#updateModelHistoryOrdersForm' ).submit(function(e) {
        e.preventDefault();
		
		
		var _formData = new FormData( document.getElementById( 'updateModelHistoryOrdersForm' ) );
		_formData.append( '__key__', 'selectModelHistoryOrders' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 약력 우선순위 갱신] 성공' );
					
					// 리스트 갱신
					selectModelHistory( data[ 'code' ] );
				}else{
					setResultFailForJSON( '[모델 약력 우선순위 갱신] 실패', data );
				}
			}
		});
    });
	
	//#################################################################
	//
	// 당선 정보
	//
	//#################################################################
	// 추가
	$( '#insertModelElectionForm' ).submit(function(e) {
        e.preventDefault();
		
		var _formData = new FormData( document.getElementById( 'insertModelElectionForm' ) );
		_formData.append( '__key__', 'insertModelElection' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 당선 추가] 성공' );
					
					// 리스트 갱신
					selectModelElection( data[ 'code' ] );
				}else{
					setResultFailForJSON( '[모델 당선 추가] 실패', data );
				}
			}
		});
    });
	// 조회
	function selectModelElection( $model_code )
	{
		var $container = $( '#modelElection>.list' );
		$container.empty();
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelElection',
				__returnType__: 'json',
				modelCode: $model_code
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 당선 조회] 성공' );
					
					// 비우기
					$container.find( '.btnDelete' ).unbind( "click" );
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>SEQ</td>";
					_tr +=  	"<td>당선일</td>";
					_tr +=  	"<td>지역구</td>";
					_tr +=  	"<td>출마당</td>";
					_tr +=  	"<td>비례대표여부</td>";
					_tr +=  	"<td>완수여부</td>";
					_tr +=  	"<td>DELETE</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;//(_listPage.current-1)*_listPage.numPerPage+1;
					for( var index in data.elec )
					{
						var _item = data.elec[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'seq' ]+"</td>";
						_tr += 		"<td>"+_item[ 'date' ]+"</td>";
						_tr += 		"<td>"+toStringByRegion( _item[ 'g_code' ] )+"</td>";
						_tr += 		"<td>"+toStringByParty( _item[ 'p_code' ] )+"</td>";
						_tr += 		"<td>"+toStringByBoolean( _item[ 'is_prop' ] )+"</td>";
						_tr += 		"<td>"+toStringByCompleted( _item[ 'com_code' ] )+"</td>";
						_tr += 		"<td>"+"<input type='button' class='btnDelete' value='DELETE' data='"+_item[ 'seq' ]+"'/>"+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$container.append( _tr );
					
					// 삭제 버튼 이벤트 등록
					$container.find( '.btnDelete' ).bind( "click", null, function(e) {
						//alert( '미구현 :: DELETE '+$(this).attr( 'data' ) );
						deleteModelElection( $model_code, $(this).attr( 'data' ) );
					});
					
				}else{
					setResultFailForJSON( '[모델 당선 조회] 실패', data );
				}
			}
			,
			'json' );
	}
	// 삭제
	function deleteModelElection( $model_code, $modelElection_seq )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'deleteModelElection',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				seq: $modelElection_seq
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[모델 당선 삭제] 성공' );
					
					// 리스트 갱신
					selectModelElection( $model_code );
				}else{
					setResultFailForJSON( '[모델 당선 삭제] 실패', data );
				}
			}
			,
			'json' );
	}
	
	
	
	//#################################################################
	//
	// 발의 법안 정보
	//
	//#################################################################
	// 추가
	$( '#insertModelBusinessForm' ).submit(function(e) {
        e.preventDefault();
		
		var _formData = new FormData( document.getElementById( 'insertModelBusinessForm' ) );
		_formData.append( '__key__', 'insertModelBusiness' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[연관 사업 추가] 성공' );
					
					// 리스트 갱신
					selectModelBussiness( data[ 'code' ] );
				}else{
					setResultFailForJSON( '[연관 사업 추가] 실패', data );
				}
			}
		});
    });
	// 조회
	function selectModelBussiness( $model_code )
	{
		var $container = $( '#modelBusiness>.list' );
		$container.empty();
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelBusiness',
				__returnType__: 'json',
				modelCode: $model_code
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[연관 사업 조회] 성공' );
					
					// 비우기
					$container.find( '.btnDelete' ).unbind( "click" );
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>SEQ</td>";
					_tr +=  	"<td>사업명</td>";
					_tr +=  	"<td>활동상태</td>";
					_tr +=  	"<td>DELETE</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;//(_listPage.current-1)*_listPage.numPerPage+1;
					for( var index in data.business )
					{
						var _item = data.business[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'seq' ]+"</td>";
						_tr += 		"<td>"+_item[ 'b_name' ]+'('+_item[ 'b_code' ]+')'+"</td>";
						_tr += 		"<td>"+toStringByAction( _item[ 'a_code' ] )+"</td>";
						_tr += 		"<td>"+"<input type='button' class='btnDelete' value='DELETE' data='"+_item[ 'seq' ]+"'/>"+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$container.append( _tr );
					
					// 삭제 버튼 이벤트 등록
					$container.find( '.btnDelete' ).bind( "click", null, function(e) {
						//alert( '미구현 :: DELETE '+$(this).attr( 'data' ) );
						deleteModelBusiness( $model_code, $(this).attr( 'data' ) );
					});
					
				}else{
					setResultFailForJSON( '[연관 사업 조회] 실패', data );
				}
			}
			,
			'json' );
	}
	// 삭제
	function deleteModelBusiness( $model_code, $modelBusiness_seq )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'deleteModelBusiness',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				seq: $modelBusiness_seq
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[연관 사업 삭제] 성공' );
					
					// 리스트 갱신
					selectModelBussiness( $model_code );
				}else{
					setResultFailForJSON( '[연관 사업 삭제] 실패', data );
				}
			}
			,
			'json' );
	}
	// 사업 목록 갱신 버튼 
	$( '#insertModelBusinessForm #btn_refreshBusiness' ).click(function(e) {
        e.preventDefault();
		
		var $list = $( '.selectBusinessList' ).empty();
		selectAllBusinesses( 0
							, 1000000
							, function( data )
							{
								setResult( '[사업 목록 갱신] 성공' );
								for( var idx in data.business )
								{
									var _code = data.business[ idx ].code;
									var _name = data.business[ idx ].name;
									$list.append( '<option value="'+_code+'">'+_name+'('+_code+')'+'</option>' );
								}
							}
							, function( data )
							{
								setResultFailForJSON( '[사업 목록 갱신] 실패', data );
							});
    });
	$( '#insertModelBusinessForm #btn_refreshBusiness' ).click();	// 한번 가져오기
	
	//#################################################################
	//
	// SNS
	//
	//#################################################################
	// 1. 입력
	$( '#insertModelSnsForm' ).submit(function(e) {
        e.preventDefault();
		
		
		var _formData = new FormData( document.getElementById( 'insertModelSnsForm' ) );
		_formData.append( '__key__', 'insertModelSns' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[SNS 링크 추가] 성공' );
					
					selectModelSns( data[ 'code' ] );
				}else{
					setResultFailForJSON( '[SNS 링크 추가] 실패', data );
				}
			}
		});
    });
	// 2. 조회
	function selectModelSns( $modelCode )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelSns',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				modelCode: $modelCode
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[SNS 링크 조회] 성공' );
					
					var $listContainer = $( '#modelSns>.list' );
					// 비우기
					$listContainer.find( '.btnDelete' ).unbind( "click" );
					$listContainer.empty();
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr += 		"<td>구분</td>";
					_tr +=  	"<td>LINK</td>";
					_tr +=  	"<td>DELETE</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;
					for( var index in data.sns )
					{
						var _item = data.sns[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+toStringBySns( _item[ 's_code' ] )+"</td>";
						_tr += 		"<td>"+_item[ 'link' ]+"</td>";
						_tr += 		"<td>"+"<input type='button' class='btnDelete' value='DELETE' data='"+_item[ 'seq' ]+"'/>"+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$listContainer.append( _tr );
					
					// 삭제 버튼 이벤트 등록
					$listContainer.find( '.btnDelete' ).bind( "click", null, function(e) {
						var $link_seq = $(this).attr( 'data' );
						//alert( '미구현 :: DELETE '+$link_seq );
						deleteSnsLink( $link_seq );
					});
				}else{
					setResultFailForJSON( '[SNS 링크 조회] 실패', data );
				}
			}
			,
			'json' 
		);
	}
	// 3. 삭제
	function deleteSnsLink( $link_seq )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'deleteModelSns',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				seq: $link_seq
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[SNS 링크 삭제] 성공' );
					
					selectModelSns( $( '#modelSns' ).find( '.modelCode' ).val() );
				}else{
					setResultFailForJSON( '[SNS 링크 삭제] 실패', data );
				}
			}
			,
			'json'
			);
	}
	
	//#################################################################
	//
	// 정치인 참조(태그)
	//
	//#################################################################
	// 1. 입력
	$( '#insertModelTagForm' ).submit(function(e) {
        e.preventDefault();
		
		
		var _formData = new FormData( document.getElementById( 'insertModelTagForm' ) );
		_formData.append( '__key__', 'insertModelTag' );
		_formData.append( '__returnType__', 'json' );
		_formData.append( 'login_member_id', login_member_id() );
		_formData.append( 'login_member_session', login_member_session() );
		
		$.ajax(
		{
			url: getGatePath(),
			data: _formData,
			dataType:'json',
			processData: false,
			contentType: false,
			type: "POST",
			success: function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[정치인 태그 추가] 성공' );
					
					selectModelTags( data[ 'code' ] );
				}else{
					setResultFailForJSON( '[정치인 태그 추가] 실패', data );
				}
			}
		});
    });
	// 2. 조회
	function selectModelTags( $modelCode )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectModelTags',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				modelCode: $modelCode
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[정치인 태그 조회] 성공' );
					
					var $listContainer = $( '#modelTags>.list' );
					// 비우기
					$listContainer.find( '.btnDelete' ).unbind( "click" );
					$listContainer.empty();
					
					// 타이틀 추가
					var _tr;
					_tr = "<thead>";
					_tr += "<tr>";
					_tr += 		"<td>NO</td>";
					_tr +=  	"<td>TAG</td>";
					_tr +=  	"<td>DELETE</td>";
					_tr += "</tr>";
					_tr += "</thead>";
					_tr += "<tbody>";
					// 리스트 추가
					var _no = 1;
					for( var index in data.tag )
					{
						var _item = data.tag[ index ];
						_tr += "<tr>";
						_tr += 		"<td>"+(_no++)+"</td>";
						_tr += 		"<td>"+_item[ 'tag' ]+"</td>";
						_tr += 		"<td>"+"<input type='button' class='btnDelete' value='DELETE' data='"+_item[ 'seq' ]+"'/>"+"</td>";
						_tr += "</tr>";
					}
					_tr += "</tbody>";
					$listContainer.append( _tr );
					
					// 삭제 버튼 이벤트 등록
					$listContainer.find( '.btnDelete' ).bind( "click", null, function(e) {
						var $seq = $(this).attr( 'data' );
						//alert( '미구현 :: DELETE '+$seq );
						deleteModelTag( $seq );
					});
				}else{
					setResultFailForJSON( '[사업 태그 조회] 실패', data );
				}
			}
			,
			'json' 
		);
	}
	// 3. 삭제
	function deleteModelTag( $seq )
	{
		$.post(
			getGatePath()
			,
			{
				__key__: 'deleteModelsTag',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session(),
				seq: $seq
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[정치인 태그 삭제] 성공' );
					
					selectModelTags( $( '#modelTags' ).find( '.modelCode' ).val() );
				}else{
					setResultFailForJSON( '[정치인 태그 삭제] 실패', data );
				}
			}
			,
			'json'
			);
	}
	// 4. 샘플 태그 가져오기
	$( '.btn_getAllModelTags' ).click(function(e) {
        e.preventDefault();
		
		$.post(
			getGatePath()
			,
			{
				__key__: 'selectAllModelTags',
				__returnType__: 'json',
				login_member_id: login_member_id(),
				login_member_session: login_member_session()
			}
			,
			function( data )
			{
				if( data.result == 'SUCCESS' )
				{
					setResult( '[정치인 사업 태그 조회] 성공' );
					
					var $selectBox = $( '.selectModelTag' ).empty();
					for( var idx in data.tag )
					{
						var _tag = data.tag[ idx ];
						var _sItem = '<option value="'+_tag+'">'+_tag+'</option>';
						$selectBox.append( _sItem );
					}
				}else{
					setResultFailForJSON( '[모든 정치인 태그 조회] 실패', data );
				}
			}
			,
			'json' );
    });
	// 한번 가져오기
	$( '.btn_getAllModelTags' ).click();
	$( '.selectModelTag' ).change(function(e) {
        var _txt = $( e.target ).parentsUntil( 'div' ).find( 'input[type=text][name=tag]' );
		_txt.val( $( e.target ).val() );
    });
	
	
	
	//#################################################################
	//
	// http://data.popong.com/ 에서 가져오기
	//
	//#################################################################
	var _popongSearchPage 	= 1;
	$('#searchModelByPopongForm' ).submit(function(e) {
        e.preventDefault();
		
		_popongSearchPage = 1;
		
		searchModelByPopong();
	})
	
	function searchModelByPopong()
	{	
		var _name = $( '#searchModelByPopongForm>[name="name"]' ).val(); 
		$.get(
			'popong/searchModel.php'
			,
			{
				name: _name,
				page: _popongSearchPage,
				per_page: 20
			}
			,
			function( data )
			{
				// 조회됨.
				/*
				address: "대구 달성군 화원읍"
				address_id: ["22", "22310", "2231011"]
				birthday: "1952-02-02"
				blog: ""
				education: "서강대학교 전자공학과졸업"
				education_id: ["7001818", null, null]
				facebook: "ghpark.kr"
				gender: "f"
				homepage: "http://www.parkgeunhye.or.kr"
				id: 195224
				image: "http://data.popong.com/people/images/2140.jpg"
				name: "박근혜"
				name_cn: "朴槿惠"
				name_en: "Park Geun-hye"
				twitter: "GH_PARK"
				wiki: "/wiki/%EB%B0%95%EA%B7%BC%ED%98%9C"
				*/
				
				var $listContainer = $( '#searchModelByPopong>.list' );
				// 비우기
				$listContainer.find( '.btnSelect' ).unbind( "click" );
				$listContainer.empty();
				
				// 타이틀 추가
				var _tr;
				_tr = "<thead>";
				_tr += "<tr>";
				_tr += 		"<td>NO</td>";
				_tr +=  	"<td>IMAGE</td>";
				_tr +=  	"<td>이름</td>";
				_tr +=  	"<td>출생연도</td>";
				_tr +=  	"<td>주소</td>";
				_tr +=  	"<td>학력</td>";
				_tr +=  	"<td>성별</td>";
				_tr +=  	"<td>SELECT</td>";
				_tr += "</tr>";
				_tr += "</thead>";
				_tr += "<tbody>";
				// 리스트 추가
				var _no = 1;
				for( var i in data.items )
				{
					var _item = data.items[ i ];
					_tr += "<tr>";
					_tr += 		"<td>"+(_no++)+"</td>";
					_tr += 		"<td>"+"<a href='"+_item[ 'image' ]+"' target='_blank'>VIEW</a>"+"</td>";
					_tr += 		"<td>"+_item[ 'name' ]+"</td>";
					_tr += 		"<td>"+_item[ 'birthday' ]+"</td>";
					_tr += 		"<td>"+_item[ 'address' ]+"</td>";
					_tr += 		"<td>"+_item[ 'education' ]+"</td>";
					_tr += 		"<td>"+_item[ 'gender' ]+"</td>";
					_tr += 		"<td>"+"<input type='button' class='btnSelect' value='SELECT' data='"+i+"'/>"+"</td>";
					_tr += "</tr>";
				}
				_tr += "</tbody>";
				$listContainer.append( _tr );
				
				// 삭제 버튼 이벤트 등록
				$listContainer.find( '.btnSelect' ).bind( "click", null, function(e) {
					var $index = parseInt( $(this).attr( 'data' ) );
					// $index 번째 선택됨... > 
					var $model = data.items[ $index ];
					var $form = $( '#insertModelForm' );
					var $sex = ($model[ 'gender' ]=='f')?1:0;
					
					$form.find( '[name="code"]' ).val( $model[ 'id' ] );
					$form.find( '[name="name"]' ).val( $model[ 'name' ] );
					$form.find( '[name="birthDate"]' ).val( $model[ 'birthday' ] );
					$form.find( '[name="education_memo"]' ).val( $model[ 'education' ] );
					$form.find( '[name="sex"]' ).val( $sex );
					$form.find( '[name="ref"]' ).val( 'data.popong.com' );
					$form.find( '[name="ref_license"]' ).val( 'CC-BY 4.0' );
				});
						
				// 페이징
				$prevButton = $("#btn_prevSearchModelByPopong" );
				$nextButton = $("#btn_nextSearchModelByPopong" );
				if( data[ 'prev_page' ] == undefined )
				{
					// 이전 버튼 숨기기
					$prevButton.hide();
				}else{
					$prevButton.show();
					$prevButton.val( "PREV PAGE "+data[ 'prev_page' ] );
				}
				if( data[ 'next_page' ] == undefined )
				{
					// 이전 버튼 숨기기
					$nextButton.hide();
				}else{
					$nextButton.show();
					$nextButton.val( "NEXT PAGE "+data[ 'next_page' ] );
				}
				
				$prevButton.unbind( 'click' );
				$prevButton.click( function( e )
				{
					_popongSearchPage--;
					
					searchModelByPopong();
				});
				$nextButton.unbind( 'click' );
				$nextButton.click( function( e )
				{
					_popongSearchPage++;
					
					searchModelByPopong();
				});				
			}
			,
			'json' );
    }
}